package factions;

import org.bukkit.Bukkit;
import org.bukkit.Location;

public class Home {
	private final Faction faction;
	private final int world;
	private final int x;
	private final int y;
	private final int z;
	private final Location location;
	
	public Home(Faction faction, String data) {
		this.faction = faction;
		String[] info = data.split(",");
		world = Integer.parseInt(info[0]);
		x = Integer.parseInt(info[1]);
		y = Integer.parseInt(info[2]);
		z = Integer.parseInt(info[3]);
		location = new Location(Bukkit.getWorlds().get(world), x, y, z);
	}
	
	public String serialize() {
		String coordinates = "" + world + "," + x + "," + y + "," + z;
		String update = "UPDATE factions SET home = '" + coordinates;
		update = update + "WHERE faction = '" + faction.name() + "'";
		return update;
	}
	
	public Location getHome() {
		return location;
	}

}
